import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import '../utils/base_color_utils.dart';
import 'shadow_view.dart';


class Clickable extends StatelessWidget {
  final Widget? child;
  final GestureTapCallback? onTap;
  final GestureTapCallback? onDoubleTap;
  final GestureLongPressCallback? onLongPress;
  final GestureTapDownCallback? onTapDown;
  final GestureTapCancelCallback? onTapCancel;
  final ValueChanged<bool>? onHighlightChanged;
  final Color? highlightColor;
  final Color? splashColor;
  final InteractiveInkFeatureFactory? splashFactory;
  final double? radius;

  final BorderRadius? borderRadius;
  final ShapeBorder? customBorder;
  final bool? enableFeedback;

  final bool? excludeFromSemantics;

  final EdgeInsets? margin;
  final EdgeInsets? padding;
  final Color? bgColor;
  final double? elevation;
  final Color? shadowColor;
  final Decoration? decoration;
  final BoxConstraints? constraints;
  final Alignment? alignment;

  final Color? selectColor;
  final bool? selected;
  final bool? materialBtn;
  final double? height;
  final double? width;

  const Clickable(
      {Key? key,
        required this.child,
        this.onTap,
        this.onDoubleTap,
        this.onLongPress,
        this.onTapDown,
        this.onTapCancel,
        this.onHighlightChanged,
        this.highlightColor,
        this.splashColor = ColorUtils.transparent,
        this.constraints,
        this.splashFactory,
        this.radius = 0,
        this.borderRadius,
        this.customBorder,
        this.enableFeedback = true,
        this.excludeFromSemantics = false,
        this.margin,
        this.padding,
        this.bgColor = ColorUtils.transparent,
        this.elevation = 0,
        this.shadowColor = ColorUtils.line,
        this.decoration,
        this.alignment,
        this.selectColor = ColorUtils.transparent,
        this.selected,
        this.materialBtn = true,
        this.height,
        this.width})
      : super(
    key: key,
  );

  @override
  Widget build(BuildContext context) {
    var elevation1 = elevation ?? 0;
    var shadowColor1 = shadowColor ?? ColorUtils.line;
    var radius1 = radius ?? 0;

    return Container(
      decoration: decoration,
      height: height,
      width: width,
      margin: margin,
      color: Colors.transparent,
      alignment: alignment,
      child: (null == onTap &&
          null == onDoubleTap &&
          null == onLongPress &&
          null == onTapDown &&
          null == onTapCancel)
          ? ShadowView(
        elevation: elevation1,
        shadowColor: shadowColor1,
        bgColor: bgColor,
        borderRadius: BorderRadius.circular(radius1),
        child: Container(
          constraints: constraints,
          padding: padding,
          child: child,
        ),
      )
          : ShadowView(
        elevation: elevation1,
        shadowColor: shadowColor1,
        bgColor: ((selected ?? false) && null != selectColor)
            ? selectColor
            : bgColor,
        // inkWell: true,
        borderRadius: BorderRadius.circular(radius1),
        child: InkWell(
          onTap: onTap,
          onDoubleTap: onDoubleTap,
          onLongPress: onLongPress,
          onTapDown: onTapDown,
          onTapCancel: onTapCancel,
          onHighlightChanged: onHighlightChanged,
          highlightColor: materialBtn == true
              ? (highlightColor ?? ColorUtils.line.withOpacity(.1))
              : Colors.transparent,
          splashColor: splashColor ?? ColorUtils.transparent,
          splashFactory: splashFactory,
          radius: materialBtn == true ? null : 0,
        //                borderRadius:borderRadius,
          borderRadius: borderRadius ?? BorderRadius.all(Radius.circular(radius1)),
          customBorder: customBorder,
          enableFeedback: enableFeedback,
          excludeFromSemantics: excludeFromSemantics ?? false,
          child: Container(
            constraints: constraints,
            padding: padding,
            color: Colors.transparent,
            child: child,
          ),
        ),
      ),
    );
  }
}
